﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    xmlns:tk="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    >

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="FlowDocumentAutoScrollViewer.xaml"/>
        <ResourceDictionary Source="FlashMisc2.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <DataTemplate DataType="{x:Type vm:TextChatRoomViewModel}">
        <Grid Margin="7, 7, 1, 20">
            <UIElement.InputBindings>
                <KeyBinding Command="{Binding SendMessageCommand}" Key="{Binding SendMessageGesture.Key}" Modifiers="{Binding SendMessageGesture.Modifiers}"/>
            </UIElement.InputBindings>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0" Grid.Row="0" Grid.RowSpan="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="3*"/>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="1*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <FlowDocumentScrollViewer Style="{StaticResource FlowDocumentAutoScrollViewerStyle}" Background="{StaticResource LightGrayBackgroundBrush}" BorderThickness="1" BorderBrush="#AAAAAA" VerticalScrollBarVisibility="Visible" Document="{Binding Path=Messages, Converter={x:Static vm:MessagesConverter.Default}}" c:Extensions.UnbindDocumentWhenSettingsUpdated="True"/>
                <GridSplitter Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Focusable="False" Height="3"/>
                <DockPanel x:Name="newMessagePanel" Grid.Row="2">
                    <Button DockPanel.Dock="Right" Focusable="False" Command="{Binding SendMessageCommand}" Margin="4, 0, 2, 1">&gt;</Button>
                    <TextBox Text="{Binding Path=NewMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="{Binding Path=SendMessageGesture, Converter={x:Static cnv:MessageCanContainCRConverter.Default}}" TextWrapping="Wrap" Background="White" Margin="0" FocusVisualStyle="{x:Null}">
                        <TextBox.Template>
                            <ControlTemplate TargetType="{x:Type TextBox}">
                                <Border Background="{TemplateBinding Background}" BorderThickness="1" BorderBrush="#AAAAAA">
                                    <ScrollViewer Margin="0" x:Name="PART_ContentHost" Padding="{TemplateBinding Padding}"/>
                                </Border>
                            </ControlTemplate>
                        </TextBox.Template>
                    </TextBox>
                </DockPanel>
                <Border x:Name="loginBanner" Grid.Row="2" CornerRadius="5" BorderThickness="1" BorderBrush="#FFCC66" Background="#FFFFE8" Visibility="Collapsed">
                    <TextBlock Margin="8, 30, 8, 3" TextWrapping="Wrap" TextTrimming="CharacterEllipsis">
                        <Hyperlink Command="{Binding ShowLogInDialogCommand}">
                            <Run Text="{c:LocalizedString s_ClickToLogIn}"/>
                        </Hyperlink>
                    </TextBlock>
                </Border>
            </Grid>

            <GridSplitter Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Stretch" Focusable="False" Width="3"/>

            <Border Grid.Column="2" Grid.Row="0" BorderBrush="#999999" BorderThickness="0, 1, 0, 1">
                <Border.Background>
                    <LinearGradientBrush StartPoint="0, 0" EndPoint="0.5, 1">
                        <GradientStop Offset="0" Color="White"/>
                        <GradientStop Offset="1" Color="#E8E7A8"/>
                    </LinearGradientBrush>
                </Border.Background>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Image Grid.Column="0" Source="{StaticResource MaleImage}" Width="15" Height="15" Margin="12, 0, 0, 0"/>
                    <Image Grid.Column="0" Source="{StaticResource FemaleImage}" Width="15" Height="15"/>
                    <TextBlock Grid.Column="1" Foreground="#564D00" Margin="2" Text="{c:LocalizedString s_Flash_MembersInThisRoom}" TextTrimming="CharacterEllipsis"/>
                </Grid>
            </Border>
            
            <ItemsControl Grid.Column="2" Grid.Row="1" ItemsSource="{Binding Users}" Background="{StaticResource GrayBackgroundBrush}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" Focusable="False">
                <ItemsControl.ItemContainerStyle>
                    <Style>
                        <Setter Property="Control.ContextMenu">
                            <Setter.Value>
                                <ContextMenu c:Extensions.Items="{Binding Converter={x:Static vm:UserMenuItemsConverter.Default}}" DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.DataContext}"/>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="FrameworkElement.ToolTip" Value="{StaticResource UserToolTip}"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Border x:Name="border" Background="#F5F5F5" Margin="1" BorderThickness="1" BorderBrush="Transparent">
                            <DockPanel>
                                <Viewbox Width="16" Height="16">
                                    <Grid>
                                        <ContentPresenter x:Name="genderIcon" Content="{Binding Path=Gender, Mode=OneTime}" HorizontalAlignment="Center" Visibility="Visible"/>
                                        <Image x:Name="isTypingIcon" Source="FlashImages\Pencil.png" Stretch="None" Visibility="Collapsed"/>
                                    </Grid>
                                </Viewbox>
                                <TextBlock Text="{Binding Path=Name, Mode=OneTime}" Foreground="#006666"/>
                            </DockPanel>
                        </Border>
                        
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=IsTyping, Mode=OneWay}" Value="true">
                                <Setter TargetName="genderIcon" Property="Visibility" Value="Collapsed"/>
                                <Setter TargetName="isTypingIcon" Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                            <Trigger SourceName="border" Property="IsMouseOver" Value="true">
                                <Setter TargetName="border" Property="BorderBrush" Value="#61687C"/>
                                <Setter TargetName="border" Property="Background" Value="#C2CFF7"/>
                            </Trigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.Template>
                    <ControlTemplate TargetType="{x:Type ItemsControl}">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                            <ScrollViewer CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                                <ItemsPresenter/>
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </ItemsControl.Template>
            </ItemsControl>

            <ProgressBar Grid.ColumnSpan="3" Grid.RowSpan="2" Width="32" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center" IsIndeterminate="True" Visibility="{Binding Path=IsLoading, Converter={StaticResource BoolToVisibilityConverter}}"/>

        </Grid>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Credentials}" Value="{x:Null}">
                <Setter TargetName="loginBanner" Property="Visibility" Value="Visible"/>
                <Setter TargetName="newMessagePanel" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>